package com.hps.spring.cloud.alibaba.controller;

import com.hps.spring.cloud.alibaba.util.SecurityUtil;
import java.util.Enumeration;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author heps
 * @since 2020/11/4 9:41
 */
@Slf4j
@RestController
@RequestMapping("/api")
public class NacosAuthProviderController {

  @GetMapping("/test")
  public String test(HttpServletRequest request) {
    Map<String, Object> currentUserInfo = SecurityUtil.getCurrentUserInfo();
    System.out.println(currentUserInfo);
    log.info(">>>>>>>>>>>>>>>>>>>>>>>>> header start! <<<<<<<<<<<<<<<<<<<<<<");
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()){
      String header = headerNames.nextElement();
      String value = request.getHeader(header);
      log.info(">>>>>>>>>>>>>>>> {} : {} <<<<<<<<<<<<<<<<<<<", header, value);
    }
    log.info(">>>>>>>>>>>>>>>>>>>>>>>>> header end! <<<<<<<<<<<<<<<<<<<<<<");
    return " test!";
  }

  @GetMapping("/hello")
  public String hello() {
    return "hello";
  }
}
